package com.galaxy.payment.api;

import com.galaxy.common.core.domain.R;
import com.galaxy.payment.domain.OrderBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 商品服务降级处理
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable cause) {
        log.error("订单服务调用失败: {}", cause.getMessage());
        return new RemoteUserService() {
            @Override
            public R<String> getOpenid(Long id) {
                return R.fail("获取用户信息失败");
            }

            @Override
            public R<Boolean> updateBalance(Long userId, BigDecimal balance) {
                return R.fail("更新用户余额失败");
            }

            @Override
            public R<Boolean> updatePoints(Long userId, Integer points) {
                return R.fail("更新用户积分失败");
            }
        };
    }
}
